<template>
  <el-icon :size="14" class="pointer mr4" :color="isCopy ? '#409eff' : '#333'">
    <CircleCheck v-if="isCopy" />
    <DocumentCopy @click="handleCopy" v-else />
  </el-icon>
</template>
<script setup lang="tsx" name="Copy">
import { DocumentCopy, CircleCheck } from "@element-plus/icons-vue";
import { copyText } from "@/utils/index";
import { ref, defineProps } from "vue";
import { ElMessage } from "element-plus";

const props = defineProps({
  copyValue: {
    required: true,
    type: String
  }
});
const isCopy = ref(false);
const handleCopy = () => {
  copyText(props.copyValue);
  isCopy.value = true;
  ElMessage({
    type: "success",
    message: "复制成功"
  });
  setTimeout(() => {
    isCopy.value = false;
  }, 1000);
};
</script>
